import axios from "axios";
import { Message } from 'element-ui';
import router from "./router";

const service = axios.create({
    baseURL: "/"
})
service.interceptors.request.use((config) => {
    config.headers['Content-Type'] = 'application/json;charset=utf-8';
    let token = window.localStorage.getItem("token");
    console.log(token,"token")
    if (token) {
        console.log("token")
        config.headers['Authorization'] ='Bearer '+  token
 
    }
    return config
})
service.interceptors.response.use((res) => {
    console.log(res)
    if (res.data.code == 504) {
        Message.warning(res.data.data)
        window.localStorage.clear();
        router.push({
            path:"/"
        })


    }
    if(res.data.code !==200){
        Message.warning(res.data.message)
        
    }
    
    return res.data
}

)
export default service